//
//  HWBookDetailCell.m
//  嗨文
//
//  Created by 响当当 on 2019/3/11.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWBookDetailCell.h"

@interface HWBookDetailCell()
@property (nonatomic, strong)UIImageView *bookImageView;//图书图片
@property (nonatomic, strong)UILabel *titleLabel;//标题
@property (nonatomic, strong)UILabel *authorLabel;//作者
@property (nonatomic, strong)UILabel *subTitleLabel;//附属标题
@property (nonatomic, strong)UILabel *clickLabel;//点击次数
@property (nonatomic, strong)UILabel *pursureLabel;//追赶人数
@property (nonatomic, strong)UILabel *shareLabel;//分享次数
@end

@implementation HWBookDetailCell

- (UIImageView *)bookImageView
{
    if (!_bookImageView)
    {
        _bookImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus,12*kUIScaleBasePlus,92*kUIScaleBasePlus,122*kUIScaleBasePlus)];
        
    }
    return _bookImageView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.bookImageView.frame)+21*kUIScaleBasePlus,17*kUIScaleBasePlus,150*kUIScaleBasePlus,0)
                                         textAligment:NSTextAlignmentLeft
                                             textClor:LCHexColor(0x363636)
                                             textFont:16*kUIScaleBasePlus];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

- (UILabel *)authorLabel
{
    if (!_authorLabel)
    {
        _authorLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.bookImageView.frame)+21*kUIScaleBasePlus,0,120*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentLeft
                                              textClor:LCHexColor(0x89898C)
                                              textFont:12*kUIScaleBasePlus];
    }
    return _authorLabel;
}

- (UILabel *)subTitleLabel
{
    if (!_subTitleLabel)
    {
        _subTitleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.bookImageView.frame)+21*kUIScaleBasePlus,0,200*kUIScaleBasePlus,13*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentLeft
                                                textClor:LCHexColor(0xA7A7A7)
                                                textFont:12*kUIScaleBasePlus];
    }
    return _subTitleLabel;
}

- (UILabel *)clickLabel
{
    if (!_clickLabel)
    {
        _clickLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,CGRectGetMaxY(self.bookImageView.frame)+22*kUIScaleBasePlus,SCREEN_WIDTH/3-1*kUIScaleBasePlus,16*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentCenter
                                                textClor:LCHexColor(0x323232)
                                                textFont:20*kUIScaleBasePlus];
        
        UILabel *titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,CGRectGetMaxY(self.clickLabel.frame)+9*kUIScaleBasePlus,SCREEN_WIDTH/3-1*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                                 textAligment:NSTextAlignmentCenter
                                                     textClor:LCHexColor(0x5B5B5B)
                                                     textFont:12*kUIScaleBasePlus];
        titleLabel.text = @"点击(次)";
        [self.contentView addSubview:titleLabel];
        
        
    }
    return _clickLabel;
}

- (UILabel *)pursureLabel
{
    if (!_pursureLabel)
    {
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/3,CGRectGetMaxY(self.bookImageView.frame)+31*kUIScaleBasePlus, 1*kUIScaleBasePlus,19*kUIScaleBasePlus)];
        lineView.backgroundColor = LCHexColor(0xE3E3E3);
        [self.contentView addSubview:lineView];
        
        
        _pursureLabel = [HWUtilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH/3+1*kUIScaleBasePlus,CGRectGetMaxY(self.bookImageView.frame)+22*kUIScaleBasePlus,SCREEN_WIDTH/3-2*kUIScaleBasePlus,16*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentCenter
                                             textClor:LCHexColor(0x323232)
                                             textFont:20*kUIScaleBasePlus];
        
        UILabel *titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH/3+1*kUIScaleBasePlus,CGRectGetMaxY(self.pursureLabel.frame)+9*kUIScaleBasePlus,SCREEN_WIDTH/3-2*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                                 textAligment:NSTextAlignmentCenter
                                                     textClor:LCHexColor(0x5B5B5B)
                                                     textFont:12*kUIScaleBasePlus];
        titleLabel.text = @"在追(人)";
        [self.contentView addSubview:titleLabel];
        
        UIView *lineBackView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(titleLabel.frame),CGRectGetMaxY(self.bookImageView.frame)+31*kUIScaleBasePlus, 1*kUIScaleBasePlus,19*kUIScaleBasePlus)];
        lineBackView.backgroundColor = LCHexColor(0xE3E3E3);
        [self.contentView addSubview:lineBackView];
    }
    return _pursureLabel;
}

- (UILabel *)shareLabel
{
    if (!_shareLabel)
    {
        _shareLabel = [HWUtilties creatLabelWithFrame:CGRectMake(SCREEN_WIDTH/3*2,CGRectGetMaxY(self.bookImageView.frame)+22*kUIScaleBasePlus,SCREEN_WIDTH/3-1*kUIScaleBasePlus,16*kUIScaleBasePlus)
                                           textAligment:NSTextAlignmentCenter
                                               textClor:LCHexColor(0x323232)
                                               textFont:20*kUIScaleBasePlus];
        
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(280*kUIScaleBasePlus,CGRectGetMaxY(self.shareLabel.frame)+9*kUIScaleBasePlus,12*kUIScaleBasePlus,12*kUIScaleBasePlus)];
        imageView.image = [UIImage imageNamed:@"earn_share"];
        [self.contentView addSubview:imageView];
        
        UILabel *titleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(imageView.frame)+5*kUIScaleBasePlus,CGRectGetMaxY(self.shareLabel.frame)+9*kUIScaleBasePlus,SCREEN_WIDTH/3-1*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                                 textAligment:NSTextAlignmentLeft
                                                     textClor:LCHexColor(0x5B5B5B)
                                                     textFont:12*kUIScaleBasePlus];
        titleLabel.text = @"分享(次)";
        [self.contentView addSubview:titleLabel];
    }
    return _shareLabel;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.bookImageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.authorLabel];
        [self.contentView addSubview:self.subTitleLabel];
        [self.contentView addSubview:self.clickLabel];
        [self.contentView addSubview:self.pursureLabel];
        [self.contentView addSubview:self.shareLabel];

    }
    return self;
}


#pragma mark - 获取数据
- (void)getDate:(NSDictionary *)dic
{
    self.bookImageView.image = [UIImage imageNamed:dic[@"bookCommon"]];
    
    self.titleLabel.text = dic[@"title"];
    [self.titleLabel sizeToFit];
    
    self.authorLabel.text = dic[@"author"];
    [self.authorLabel setY:CGRectGetMaxY(self.titleLabel.frame)+10*kUIScaleBasePlus];
    
    NSString *subTitle = dic[@"subTitle"];
    self.subTitleLabel.attributedText = [subTitle addAttriButedString:subTitle
                                                                Color:LCHexColor(0xFF771A)
                                                                 Font:[UIFont systemFontOfSize:12*kUIScaleBasePlus]
                                                                 rang:NSMakeRange(subTitle.length-3,3)];
    [self.subTitleLabel setY:CGRectGetMaxY(self.authorLabel.frame)+5*kUIScaleBasePlus];
    
    
    CGFloat marign = 15*kUIScaleBasePlus;
    NSArray *tagArr = dic[@"tag"];
    CGFloat oneWidth = 0;
    CGFloat twoWidth = 0;

    for (int i=0;i<tagArr.count;i++)
    {
        UILabel *tagLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.bookImageView.frame)+21*kUIScaleBasePlus,105*kUIScaleBasePlus,0,16*kUIScaleBasePlus)
                                               textAligment:NSTextAlignmentCenter
                                                   textClor:LCHexColor(0xFD5567)
                                                   textFont:12*kUIScaleBasePlus];
        tagLabel.layer.masksToBounds = YES;
        tagLabel.layer.cornerRadius = 1;
        tagLabel.layer.borderWidth = 1;
        tagLabel.layer.borderColor = LCHexColor(0xFD5567).CGColor;
        tagLabel.text = tagArr[i];
        [tagLabel sizeToFit];
        
        switch (i)
        {
            case 0:
            {
                oneWidth = tagLabel.frame.size.width;
                [tagLabel setWidth:oneWidth+10*kUIScaleBasePlus];
            }
                break;
            case 1:
            {
                [tagLabel setX:oneWidth+marign+CGRectGetMaxX(self.bookImageView.frame)+21*kUIScaleBasePlus];
                twoWidth = tagLabel.frame.size.width;
                [tagLabel setWidth:twoWidth+10*kUIScaleBasePlus];
            }
                break;
            case 2:
            {
                [tagLabel setX:twoWidth+marign+oneWidth+marign+CGRectGetMaxX(self.bookImageView.frame)+21*kUIScaleBasePlus];
                [tagLabel setWidth:tagLabel.frame.size.width+10*kUIScaleBasePlus];

            }
                break;
            default:
                break;
        }
        
        [self.contentView addSubview:tagLabel];
    }
    
    self.clickLabel.text = dic[@"click"];
    self.pursureLabel.text = dic[@"pursure"];
    self.shareLabel.text = dic[@"share"];

}

@end
